home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 11078 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.3 KB  |  50 lines

  1. Path: news.halcyon.com!usenet
  2. From: normanb@halcyon.com (Norm Bryar)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: [Q] how declare a Template class as a friend
  5. Date: Tue, 12 Mar 1996 16:35:11 GMT
  6. Organization: Northwest Nexus Inc.
  7. Message-ID: <4i492l$qtc@news.halcyon.com>
  8. References: <Dnx660.1Ex@news.uwindsor.ca> <davef-1103961104160001@128.128.173.90>
  9. NNTP-Posting-Host: blv-pm3-ip12.halcyon.com
  10. X-Newsreader: Forte Free Agent 1.0.82
  11.  
  12. davef@mbl.edu (Dave Fernandes) wrote:
  13.  
  14. >In article <Dnx660.1Ex@news.uwindsor.ca>, saed@engn.uwindsor.ca wrote:
  15.  
  16. >> Hi all,
  17. >> 
  18. >> --- How do you declare a template class to be a friend of
  19. >>     another non-template class?
  20. >> 
  21. >> template <class T> class A {};  // the template class A<T's>
  22. >> class B { friend class A };     // won't do it, A is not a class
  23. >> template <class V> class B { friend class A<V> };       // B<V's> are
  24. >not wanted
  25.  
  26. >What if you declare your template class A as a subclass of some other
  27. >abstract class C, and have C be a friend of B?
  28.  
  29. >class C {};
  30. >template <class T> class A : public C {};
  31. >class B {friend class C};
  32.  
  33. >I'm not sure, but I think this should work.
  34.  
  35. You forward declare template classes as follows:
  36.  
  37. template <class T>
  38. class A;
  39.  
  40. Have you tried the same with the friend keyword?
  41.  
  42. class B 
  43. {
  44.     friend template <class T> class A;
  45.     ...
  46. };
  47.  
  48.                 --Norm 
  49.  
  50.